package com.wx.controller;

import java.util.Map;

import org.apache.http.client.HttpClient;
import org.elasticsearch.cluster.routing.allocation.decider.Decision.Single;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import com.wx.kit.Sign;
import com.wx.kit.WxKit;

import net.minidev.json.JSONValue;

@Controller
public class RedirectController {

	/**
	 * 链接参数DEMO
	 * https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect
	 * 
	 * @desc 回掉接口authorize 获取用户信息
	 * @param code换取网页授权access_token
	 * @return
	 */
	@GetMapping(path = "/authorizeCallBack")
	public String authorizeCallBack(String code) {
		String authoStr = WxKit.authorizationCode(code);
		Map<String, Object> authoMap = (Map<String, Object>) JSONValue.parse(authoStr);
		String accessToken = authoMap.get("access_token").toString();
		String openid = authoMap.get("openid").toString();
		String userDate = WxKit.getUnionIdByAuthorizationCode(accessToken, openid);
		System.out.println(userDate);
		return "test";
	}

	@GetMapping(path = "transmit")
	public void transmit() {
//		Sign.sign(jsapi_ticket, url);
	}

}
